package com.example.myapplication;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private Button login_btn,zhuce_btn;
    private EditText password,username;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        indata();
        init();
        intenttoactivity();

    }

    private void indata() {
        SharedPreferences getsp=getSharedPreferences("users",MODE_PRIVATE);
        String usernameget=getsp.getString("username","");
        String passwordget=getsp.getString("password","");
        password.setText(passwordget);
        username.setText(usernameget);
    }

    private void intenttoactivity() {
        login_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String password1=password.getText().toString();
                String username1=username.getText().toString();

                Intent intent=new Intent(MainActivity.this,LoginActivity.class);
                SharedPreferences.Editor SP=getSharedPreferences("users",MODE_PRIVATE).edit();
                SP.putString("username",username1);
                SP.putString("password",password1);
                SP.apply();
                Toast.makeText(MainActivity.this,"sss",Toast.LENGTH_LONG).show();
                startActivity(intent);
            }
        });

    }
    private void init() {
        login_btn=findViewById(R.id.login_button);
        zhuce_btn=findViewById(R.id.zhuce_button);
        password=findViewById(R.id.password_edt);
        username=findViewById(R.id.username_edt);
    }
}
